home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Gershgorin disks.
-
- // Syntax: gersh ( A )
-
- // Description:
-
- // gersh(A) draws the Gershgorin disks for the matrix A. The
- // eigenvalues are plotted as crosses `x'.
-
- // Alternative usage: gersh(A, 1) suppresses the plot and returns
- // the data in G, with A's eigenvalues in E.
- //
- // Try: gersh(lesp(n)) and gersh(smoke(n,1)).
-
- // This file is a translation of gersh.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- // Dependencies
- require seqa cpltaxes
-
- //-------------------------------------------------------------------//
-
- gersh = function (A, noplot)
- {
- local (A, noplot)
- global (pi)
-
- if (diff (size (A))) { error ("Matrix must be square."); }
-
- n = max (size (A));
- m = 40;
- G = zeros (m,n);
-
- d = diag (A);
- r = sum ( abs ( A.'-diag (d) ) )';
- e = eig (A).val.';
-
- radvec = exp (1i * seqa (0, 2*pi,m)');
-
- for (j in 1:n)
- {
- G[;j] = d[j]*ones (size (radvec)) + r[j]*radvec;
- }
-
- if (!exist (noplot))
- {
- ax = cpltaxes (G[:]);
- plimits (ax[1], ax[2], ax[3], ax[4]);
- plaxis (); plimits (); plaspect (1);
- plstyle ("line");
- for (j in 1:n)
- {
- plimits (ax[1], ax[2], ax[3], ax[4]);
- plot ([ real (G[;j]), imag(G[;j]) ]); // Plot the disks.
- subplot (0);
- }
- plstyle ("point");
- plot ([ real (e), imag (e) ]); // Plot the eigenvalues too.
- }
-
- return << G=G; e=e >>;
- };
-